import defs


def main(num: str) -> str:
    status, num = defs.str_to_int(num)
    if status:
        u = defs.find_nearest_prime(num+5)
        m = defs.find_nearest_prime(num)
        if num - m > u - num:
            return str(u)
        return str(m)
    else:
        return num


print(main(input()))
